# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=hlint
pkgver=3.6
pkgrel=0
pkgdesc="Linter for Haskell source code"
url="https://github.com/ndmitchell/hlint"
arch="x86_64 aarch64" # limited by ghc
license="BSD-3-Clause"
makedepends="ghc cabal"
options="net"
source="https://hackage.haskell.org/package/hlint-$pkgver/hlint-$pkgver.tar.gz
	cabal.project.freeze"

# Directory were cabal files are stored.
export CABAL_DIR="$srcdir/dist"

# Needed to fix build on aarch64.
export PATH="$PATH:/usr/lib/llvm14/bin"

cabal_update() {
	cd $builddir
	cabal v2-update
	(
		cd "$builddir"
		cabal v2-freeze --shadow-installed-packages
		mv cabal.project.freeze "$startdir/"
	)
}

prepare() {
	default_prepare
	ln -sf "$srcdir/cabal.project.freeze" \
		"$builddir/cabal.project.freeze"
}

build() {
	cabal v2-update
	cabal v2-build hlint:exes \
		--jobs=${JOBS:-1} \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--sysconfdir=/etc
}

package() {
	# See https://github.com/haskell/cabal/issues/6919#issuecomment-761563498
	cabal list-bin hlint:exes | xargs install -Dm755 -t "$pkgdir"/usr/bin
}

sha512sums="
3c1ee2969fc96aac87c8a69b11497696dd6450024d2254860a8e3181f988254794a65ecabed9d97fc2bcdc61bbd6abdf6809fe535c4121fad17ad1dc1dfe8d9e  hlint-3.6.tar.gz
fa7ff9eecd5dd2c6900d2bf058f5ef4200c90dc4b7389d50de1a2a695ca0ee8264ce87783cca61409fb25e8667c8fef32ce71f9c168d794a8494f9a55b3fb805  cabal.project.freeze
"
